package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class HJ33_相同数字的积木游戏1 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/33.txt"));
    int N = in.nextInt();
    Map<Integer, Integer> map = new HashMap<>();
    int maxDistance = -1;
    for (int i = 0; i < N; i++) {
      int now = in.nextInt();
      if (map.containsKey(now)) {
        int tmpDistance = i - map.get(now);
        if (tmpDistance > maxDistance) {
          maxDistance = tmpDistance;
        }
      } else {
        map.put(now, i);
      }
    }
    System.out.println(maxDistance);
  }
}
